/*
 * @lc app=leetcode.cn id=1 lang=cpp
 *
 * [1] 两数之和
 */
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
// @lc code=start
/* class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        int n=nums.size();
        for (int i = 0; i < n;++i)
        {
            for (int j = i+1; j < n; ++j)
            {
                if(nums[i]+nums[j]==target){
                    return {i,j};
                }
            }
            
        }
        return {};
    }
}; */

class Solution{
    public:
    vector<int> twoSum(vector<int>& nums,int target){
        unordered_map<int,int> hashmap;
        for(int i=0;i<nums.size();++i){
            auto iter=hashmap.find(target-nums[i]);
            if(iter!=hashmap.end()){
                return {iter->second,i};
            }
            hashmap.insert({nums[i],i});
        }
        return {};
    }
};
// @lc code=end

